package com.dfbz.bigdata.modules.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dfbz.bigdata.common.utils.R;
import com.dfbz.bigdata.modules.system.doman.CommonComputer;
import com.dfbz.bigdata.modules.system.service.CommonComputerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@RestController
@RequestMapping("/computer")
@Slf4j
public class CommonComputerController {

    @Autowired
    private CommonComputerService commonComputerService;


//    得到装修计算器的list
    @GetMapping
    public R<Page<CommonComputer>> getComputerList(String placeNum, int currentPage, int pagesizes){
        Page<CommonComputer> page=new Page<>(currentPage,pagesizes);

        LambdaQueryWrapper<CommonComputer> lqw=new LambdaQueryWrapper();
        lqw.like(CommonComputer::getComputerPlace,placeNum);

        commonComputerService.page(page,lqw);

        return R.success(page);
    }


    @DeleteMapping("/{computerId}")
    public R<String> delete(@PathVariable Long computerId){
        boolean b = commonComputerService.removeById(computerId);
        if (b){
            return R.success("删除成功^_^!!!!!");
        }
        else return  R.error("系统繁忙-_-!!");
    }



    @PostMapping
    public R<String> saveComputer(@RequestBody CommonComputer commonComputer){

        log.info("computer{}",commonComputer);
        commonComputer.setCreateTime(new Date());
        commonComputer.setUpdateTime(new Date());

        boolean flag = commonComputerService.save(commonComputer);

        if(flag){
            return R.success("成功！！");
        }else {
           return R.error("服务器繁忙！！");
        }
//              return   R.success("test");
    }
}
